package mirrormonkey.rpc.tools.singlecall.entities;

import mirrormonkey.rpc.tools.entities.SyncBox;
import mirrormonkey.rpc.tools.listeners.MakeVisibleListener;
import mirrormonkey.rpc.tools.singlecall.specs.Rotatable;

import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;

public class RotatableBox extends SyncBox implements Rotatable {

	public MakeVisibleListener visibilityListener;

	public Object unreliableNullSet;
	public Object nullSet;

	public Rotatable setByCall;

	public Rotatable nulledByCall;

	public RotatableBox(Vector3f pos) {
		super(pos);
		unreliableNullSet = new Object();
		nullSet = new Object();
		setByCall = null;
		nulledByCall = this;
	}

	public void setVisibilityListener(MakeVisibleListener visibilityListener) {
		this.visibilityListener = visibilityListener;
	}

	@Override
	public void setRotation(Quaternion rot) {
		setLocalRotation(rot);
	}

	@Override
	public void setNullObject(Object shouldBeNull) {
		nullSet = shouldBeNull;
	}

	@Override
	public void unreliableNullCall(Object shouldBeNull) {
		unreliableNullSet = shouldBeNull;
	}

	@Override
	public void setLoadParams(ColorRGBA color, float scale, Vector3f pos) {
		setMaterial(visibilityListener.createMaterial(color));
		this.setLocalScale(scale);
		this.setLocalTranslation(pos);
	}

	@Override
	public void idAwareCall(RotatableBox box) {
		setByCall = box;
		nulledByCall = box;
		if (box != null) {
			setLocalTranslation(box.getLocalTranslation());
		}
	}

	@Override
	public void interfaceBasedIdAwareCall(Rotatable box) {
		setByCall = box;
		setLocalTranslation(((Geometry) box).getLocalTranslation());
	}

}
